package sbc.ms;

import java.util.List;

import org.xvsm.api.core.Capi;
import org.xvsm.api.core.ContainerRef;
import org.xvsm.api.core.CoordinationTypes;
import org.xvsm.api.core.Entry;
import org.xvsm.api.core.Tuple;
import org.xvsm.client.ClientCapi;

public class Lister {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("URL needed!");
			System.out.println("Usage: java -cp <classpath> sbc.ms.Lister http://localhost:8080/xvsm/xvsm");
			System.exit(1);
		}
		
		try {
			Capi capi = new ClientCapi(args[0]);
			capi.init(false);
			
			ContainerRef cref = Util.getOrCreateNamedContainer(capi, "Container", CoordinationTypes.FIFO);
			System.out.println("CREF: " + cref);
			
			
			/*
			 * take all entries out of FIFO Space
			 * (including deletion)
			 */
			for (;;) {
				List<Entry> take = capi.take(cref);
				
				Tuple t = (Tuple) take.get(0);
				
				List<Entry> elements = t.getValue();
		
				System.out.println(elements.get(0).getValue() + " "
					+ elements.get(1).getValue());
			}
		}
		catch (Exception e) {
			
		}
	}
}
